﻿using Dapper;
using Himp.TaskScheduling.Datas;
using Himp.TaskScheduling.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Repositories.Dapper;
using Volo.Abp.EntityFrameworkCore;

namespace Himp.RL
{
    public class SamplePreparationRecRepository :
        DapperRepository<RLWebDbContext>, ITransientDependency
    {
        #region SQL

        public const string SQL_SAMPLEPREPARATIONREC = @"
            SELECT
            *
            FROM
            HY_SamplePreparationRec
            WHERE
            CONVERT(VARCHAR(10), [EndTime], 120) = CONVERT(VARCHAR(10), GETDATE(), 120)
            ";

        #endregion

        public SamplePreparationRecRepository(IDbContextProvider<RLWebDbContext> dbContextProvider)
            : base(dbContextProvider)
        {
        }

        public virtual async Task<List<SamplePreparationRec>> GetAllPersonNamesAsync()
        {
            var dbConnection = await GetDbConnectionAsync();
            return (await dbConnection.QueryAsync<SamplePreparationRec>(SQL_SAMPLEPREPARATIONREC,
                transaction: await GetDbTransactionAsync())
            ).ToList();
        }

        public virtual async Task<int> UpdatePersonNamesAsync(string name)
        {
            var dbConnection = await GetDbConnectionAsync();
            return await dbConnection.ExecuteAsync(
                "update People set Name = @NewName",
                new { NewName = name },
                await GetDbTransactionAsync()
            );
        }
    }
}
